package com.example.login.Service;

import com.example.login.Mapper.UserMap;
import com.example.login.Pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service("UserService")
public class UserService {
    @Autowired
    UserMap userMap;
    public boolean isUser(String username, String password,
                          HttpSession httpSession)//返回是否通过
    {
        User user= userMap.getUserByName(username);
        if(user==null||user.getId()==-1)return false;
        else if(!user.getPasswords().equals(password))return false;
        else//成功登录
        {
            httpSession.setAttribute("user",user);
            userMap.login(user.getId());
            return true;
        }
    }
    //public JdbcTemplate jdbcTemplate=new JdbcTemplate();
    public void Register(String username,String password)//返回是否通过
    {

        userMap.Register(username, password);
    }

    public void updateName(String username,int user_id)
    {
        userMap.updateName(username,user_id);
    }
}
